// Pinia 仓库
/**
 * 定义 store仓库语法：
 *          - defineStore（仓库的名称， () => {数据逻辑....}）
 * 
 */

import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import piniaPersistConfig from "@/utils/persist"

export const userCounterStore = defineStore('counter', () => {
	// 声明仓库数据
	const count = ref(100)
	const count2 = ref(200)
	

	// 仓库处理函数actions（就相当于普通函数）
	const handleAdd = () => count2.value++
	const handleSub = () => count.value--

	// 计算属性
	const number = computed(() => count.value * 2)

	// 声明仓库数据
	const message = ref('Pinia 仓库')




	// return 仓库数据，外部调用
	return {
		count,
		count2,
		handleAdd,
		handleSub,
		number,
		message,
	}
}, {
	persist: piniaPersistConfig('counterStore')
}
)